const { BrowserWindow, dialog } = require("electron").remote;
const path = require("path");

const processCrashBtn = document.getElementById("process-crash");

processCrashBtn.addEventListener("click", (event) => {
  const crashWinPath = path.join(
    "file://",
    __dirname,
    "../../sections/windows/process-crash.html"
  );
  let win = new BrowserWindow({
    width: 400,
    height: 320,
    webPreferences: {
      nodeIntegration: true,
    },
  });

  win.webContents.on("crashed", () => {
    const options = {
      type: "info",
      title: "渲染器进程崩溃",
      message: "这个进程已经崩溃.",
      buttons: ["重载", "关闭"],
    };

    dialog.showMessageBox(options, (index) => {
      if (index === 0) win.reload();
      else win.close();
    });
  });

  win.on("responsive", function () {
    // 当窗口再次响应时做些什么
    console.log("再次响应");
  });

  win.on("close", () => {
    win = null;
  });
  win.loadURL(crashWinPath);
  win.show();
});
